home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: newbie--what's wrong with this?
- Date: Sun, 28 Jan 96 22:27:34 GMT
- Organization: none
- Message-ID: <822868054snz@genesis.demon.co.uk>
- References: <4ee8gk$kes@shiva.usa.net>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4ee8gk$kes@shiva.usa.net> jhamp@earth.usa.net "James Hamp" writes:
-
- >Rule->CompRule = (COMPARERULE *)malloc(2 * sizeof(COMPARERULE));
- >
- >/* Initialize first compare rule, then... */
- >
- >Rule->CompRule++;
- >^^^^^^^^^^^^^^^^^ This didn't work--when I initialized the second rule
- > (or so I thought), it went into the first rule.
-
- Actually it did work except that it did more than you expected. This
- increments Rule->CompRule and therefore makes that point to the second rule.
- To access the first rule using the pointer you would then need something
- like Rule->CompRule[-1] and to access the 2nd you need Rule->CompRule[0].
-
- >Thinking I had a precedence problem, I tried
- >
- >(Rule->CompRule)++;
- >
- >and the same thing happened.
-
- Right - that means the same thing.
-
- >I know I'm being stupid here--my try that worked was
- >to initialize the second rule with Rule->CompRule[1].members. Since I
- >made it work, the code's okay, but I'd like to know what I'm not under-
- >standing.
-
- Right, that simply accesses/updates the 2nd entry without changing the
- pointer. Therefore future uses of that pointer worked as you expected.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-